var fs = require('fs');
var fileName = './config/db.json';

function db() {
    this.data = require(fileName);
    console.log('db:', this.data);
    this.catch = {
        number: 0
    };
}

db.prototype.set = function(key, value) {
    this.data[key] = value;
    try {
        fs.writeFileSync(fileName, JSON.stringify(this.data));
    } catch (e) {
        return 1;
    }

    delete require.cache[require.resolve(fileName)];

    this.data = require(fileName);
    return 0;
};

module.exports = new db();